package sing.rabbit.provider;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.amqp.RabbitTemplateConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Scope;
import org.springframework.scheduling.annotation.EnableScheduling;

/**
 * @author xing
 * @date 2022/9/7 17:20
 */
@SpringBootApplication(scanBasePackages = {"sing.rabbit.provider", "sing.rabbit.common"})
@EnableScheduling
@Slf4j

public class RabbitProviderApplication {

    /**
     * 这里使用 @Scope 设为多例 是 为了解决报错：Only one ConfirmCallback is supported by each RabbitTemplate
     */
    @Bean
    @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    public RabbitTemplate myRabbitTemplate(RabbitTemplateConfigurer configurer, ConnectionFactory connectionFactory) {
        RabbitTemplate template = new RabbitTemplate();
        configurer.configure(template, connectionFactory);
        return template;
    }

    public static void main(String[] args) {
        SpringApplication.run(RabbitProviderApplication.class, args);
    }
}
